package org.jeecg.modules.submodules.util;

import org.apache.shiro.SecurityUtils;
import org.jeecg.common.system.vo.LoginUser;
import org.jeecgframework.poi.excel.def.NormalExcelConstants;
import org.jeecgframework.poi.excel.entity.ExportParams;
import org.jeecgframework.poi.excel.view.JeecgEntityExcelView;
import org.springframework.web.servlet.ModelAndView;

import java.util.List;

/**
 *  @author  wenhao0727
 *  @date 2020/5/28
 *
 *  导出excel表的工具类，基于autopoi
 */
public class ExportExcelUtil {
    public static ModelAndView exportExcel(List<?> object, Class<?> clazz, String title){
        ModelAndView mv = new ModelAndView(new JeecgEntityExcelView());
        LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
        //导出文件名称
        mv.addObject(NormalExcelConstants.FILE_NAME,"导出Excel文件名字");
        //注解对象Class
        mv.addObject(NormalExcelConstants.CLASS,clazz);
        //自定义表格参数
        mv.addObject(NormalExcelConstants.PARAMS, new ExportParams(title + "报表", "导出人:" + sysUser.getRealname(), title));
        //导出数据列表
        mv.addObject(NormalExcelConstants.DATA_LIST,object);
        return mv;
    }
}
